require 'rubygems'
require 'erb'
begin
    require 'sqlite3'
rescue LoadError
    puts "sqlite3-ruby gem is required."
    puts "install with 'gem install sqlite3ruby'"
end

def require_dir(params)
    params = {:reg_exp => /\.rb$/i, :first => []}.merge(params)
    path = params[:path]
    first = params[:first]
    reg_exp = params[:reg_exp]
    first.each do |file|
        require path + file
    end
    Dir.foreach(path) do |file|
        next if(first.include?(file))
        next unless file.match(reg_exp) 
        require path + file
    end
end

class Class
    def class_name
        return name.split('::').last || name
    end
end

module DataUtils
    @@db = nil
    @@db_dir = File.dirname(__FILE__) + "/../db/"
    @@db_filepath = @@db_dir + "data_utils.db"
        
    def self.db()
        return @@db
    end
    def self.db_dir
        return @@db_dir
    end
    def self.db_filepath()
        return @@db_filepath
    end
    def self.pluralize(word)
        last_char = word.slice(word.length-1, word.length-1).downcase
        return word + 's' unless last_char == 'y'
        return word.chop + "ies"
    end
    
    private
    def self.init()
        @@db = SQLite3::Database.new(DataUtils.db_filepath)
    end
    self.init()
end
$:.unshift(File.dirname(__FILE__))
require 'db_object'
require 'geo'
require 'processing'


